Download
FAQ
History
HomeHomeNext API
Search
Feedback
Divider

Configuring Web Modules

Web applications are configured via elements contained in the Web application deployment descriptor. The deploytool utility generates the descriptor when you create a WAR and adds elements when you create Web components and associated classes. You can modify the elements via the inspectors associated with the WAR.

The following sections give a brief introduction to the Web application features you will usually want to configure. A number of security parameters can be specified; these are covered in Web-Tier Security.

In the following sections, some examples demonstrate procedures for configuring the Hello, World application. If Hello, World does not use a specific configuration feature, the section gives references to other examples that illustrate how the deployment descriptor element and describes generic procedures for specifying the feature using deploytool. Extended examples that demonstrate how to use deploytool are in The Example Servlets, The Example JSP Pages, and The Example JSP Pages.

Mapping URLs to Web Components

When a request is received by the Web container it must determine which Web component should handle the request. It does so by mapping the URL path contained in the request to a Web application and a Web component. A URL path contains the context root and an alias:

http://host:port/context_root/alias 

Setting the Context Root

A context root identifies a Web application. A context root must start with a forward slash '/' and end with a string. For example, to set the context root of the hello1 application with deploytool:

  1. Select the hello1 WAR.
  2. Select the General tab.
  3. In the Context Root field, enter /hello1.

Setting the Component Alias

The alias identifies the Web component that should handle a request. The servlet path must start with a forward slash '/' and end with a string or a wildcard expression with an extension (*.jsp, for example). Since Web containers automatically map an alias that ends with *.jsp, you do not have to specify an alias for a JSP page unless you wish to refer to the page by a name other than its file name. In the hello2 example, the greeting page has a alias, but response.jsp is called by name.

To set up the mappings for the servlet version of the Hello application with deploytool:

  1. Expand the hello1 WAR node.
  2. Select the GreetingServlet Web component.
  3. Select the Aliases tab.
  4. Click Add to add a new mapping.
  5. Type /greeting in the aliases list.
  6. Select the ResponseServlet Web component.
  7. Click Add.
  8. Type /response in the aliases list.

Declaring Welcome Files

The welcome files mechanism allows you to specify a list of files that the Web container will use for appending to a request for a URL (called a valid partial request) that is not mapped to a Web component.

For example, suppose you define a welcome file welcome.html. When a client requests a URL such as host:port/webapp/directory, where directory is not mapped to a servlet or JSP page, the file host:port/webapp/directory/welcome.html is returned to the client.

If a Web container receives a valid partial request, the Web container examines the welcome file list and appends each welcome file in the order specified to the partial request and checks whether a static resource or servlet in the WAR is mapped to that request URL. The Web container then sends the request to the first resource in the WAR that matches.

If no welcome file is specified, the J2EE 1.4 Application Server will use a file named index.XXX, where XXX can be html or jsp, as the default welcome file. If there is no welcome file and no file named index.XXX, the application server returns a directory listing.

To specify welcome files with deploytool:

  1. Select the WAR.
  2. Select the File Refs tab in the WAR inspector.
  3. Click Add in the Welcome Files pane.
  4. Select the welcome file from the drop-down list.

Setting Initialization Parameters

The Web components in a Web module share an object that represents their application context (see Accessing the Web Context). You can pass initialization parameters to the context or to a Web component. To add a context parameter with deploytool:

  1. Select the WAR.
  2. Select the Context tab in the WAR inspector.
  3. Click Add.

For an example context parameter, see The Example JSP Pages.

To add a Web component initialization parameter with deploytool:

  1. Select the Web component.
  2. Select the Init Param. tab in the WAR inspector.
  3. Click Add.

Specifying Error Mappings

You can specify a mapping between the status code returned in an HTTP response or a Java programming language exception returned by any Web component and a Web resource (see Handling Errors). To set up the mapping with deploytool:

  1. Select the WAR.
  2. Select the File Refs tab in the WAR inspector.
  3. Click Add in the Error Mapping pane.
  4. Enter the HTTP status code (see HTTP Responses) or fully-qualified class name of an exception in the Error/Exception field.
  5. Enter the name of a resource to be invoked when the status code or exception is returned. The name should have a leading forward slash /.

Note: You can also define error pages for a JSP page contained in a WAR. If error pages are defined for both the WAR and a JSP page, the JSP page's error page takes precedence.


For an example error page mapping, see The Example Servlets.

Declaring References to Environment Entries, Resource Environment Entries, or Resources

If your Web components reference environment entries, resource environment entries, or resources such as databases, you must declare the references in the Web application deployment descriptor. To add a reference to a resource with deploytool:

  1. Select the WAR.
  2. Select the Environment, Enterprise Bean Refs, Resource Env. Refs, or Resource Refs tab in the WAR inspector.
  3. Click Add to add a new reference.
  4. Type a JNDI name for the resource.
  5. Choose the type of the resource.
  6. Choose whether the container or the application performs authentication when the resource is accessed.
  7. Choose whether the resource can be shared by more than one Web application.

For an example resource reference, see Configuring the Web Application to Reference a Data Source with JNDI.

Divider
Download
FAQ
History
HomeHomeNext API
Search
Feedback
Divider

All of the material in The J2EE 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.